package com.marvels.financial.consum.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.consum.FinancialConsumerSystemApi;
import com.marvels.financial.loan.dto.McsmSystemParam;
import com.marvels.financial.loan.dto.SysUserDTO;
import com.marvels.system.common.api.SystemParamsApi;
import com.marvels.system.permission.service.SysUserService;

@Component
public class FinancialConsumerSystemImpl implements FinancialConsumerSystemApi{

	@Autowired
	private SystemParamsApi systemParamsApi;
	
	@Autowired
	private SysUserService sysUserService;
	
	@Override
	public List<McsmSystemParam> paramList(McsmSystemParam mcsmSystemParam) {
		try {
			List<com.marvels.system.permission.dto.McsmSystemParam> apiResult = systemParamsApi.paramList(mcsmSystemParam.getParamNames());
			List<McsmSystemParam> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), McsmSystemParam.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerSystemApi.paramList direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerSystemApi.paramList error", e);
			return null;
		}
	}

	@Override
	public SysUserDTO querySysUser(Integer userId) {
		try {
			com.marvels.system.permission.dto.SysUserDTO param = new com.marvels.system.permission.dto.SysUserDTO();
			param.setUserId(userId);
			com.marvels.system.permission.dto.SysUserDTO apiResult = sysUserService.getUserById(param);
			SysUserDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), SysUserDTO.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerSystemApi.querySysUser direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerSystemApi.querySysUser error", e);
			return null;
		}
	}

}
